from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-13 14:02:26.711831
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 13, Aug, 2022
Time: 14:02:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1224
Nobs: 747.000 HQIC: -50.4642
Log likelihood: 9478.90 FPE: 9.78601e-23
AIC: -50.6785 Det(Omega_mle): 8.68217e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.293887 0.055334 5.311 0.000
L1.Burgenland 0.108589 0.036731 2.956 0.003
L1.Kärnten -0.106839 0.019474 -5.486 0.000
L1.Niederösterreich 0.208203 0.076616 2.718 0.007
L1.Oberösterreich 0.109280 0.074840 1.460 0.144
L1.Salzburg 0.254475 0.039248 6.484 0.000
L1.Steiermark 0.040850 0.051239 0.797 0.425
L1.Tirol 0.107718 0.041560 2.592 0.010
L1.Vorarlberg -0.061798 0.035643 -1.734 0.083
L1.Wien 0.050392 0.066181 0.761 0.446
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061134 0.115567 0.529 0.597
L1.Burgenland -0.033771 0.076714 -0.440 0.660
L1.Kärnten 0.047266 0.040672 1.162 0.245
L1.Niederösterreich -0.176069 0.160015 -1.100 0.271
L1.Oberösterreich 0.407491 0.156306 2.607 0.009
L1.Salzburg 0.287675 0.081971 3.509 0.000
L1.Steiermark 0.108053 0.107015 1.010 0.313
L1.Tirol 0.311839 0.086800 3.593 0.000
L1.Vorarlberg 0.024822 0.074442 0.333 0.739
L1.Wien -0.030784 0.138221 -0.223 0.824
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188281 0.028392 6.631 0.000
L1.Burgenland 0.090000 0.018847 4.775 0.000
L1.Kärnten -0.008762 0.009992 -0.877 0.381
L1.Niederösterreich 0.259724 0.039312 6.607 0.000
L1.Oberösterreich 0.138185 0.038401 3.598 0.000
L1.Salzburg 0.045453 0.020138 2.257 0.024
L1.Steiermark 0.020916 0.026291 0.796 0.426
L1.Tirol 0.093008 0.021325 4.362 0.000
L1.Vorarlberg 0.056696 0.018289 3.100 0.002
L1.Wien 0.117647 0.033958 3.465 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107403 0.028866 3.721 0.000
L1.Burgenland 0.045639 0.019162 2.382 0.017
L1.Kärnten -0.013779 0.010159 -1.356 0.175
L1.Niederösterreich 0.189743 0.039968 4.747 0.000
L1.Oberösterreich 0.301251 0.039042 7.716 0.000
L1.Salzburg 0.109757 0.020475 5.361 0.000
L1.Steiermark 0.103446 0.026730 3.870 0.000
L1.Tirol 0.105516 0.021681 4.867 0.000
L1.Vorarlberg 0.069298 0.018594 3.727 0.000
L1.Wien -0.019106 0.034525 -0.553 0.580
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126476 0.052555 2.407 0.016
L1.Burgenland -0.050072 0.034887 -1.435 0.151
L1.Kärnten -0.040782 0.018496 -2.205 0.027
L1.Niederösterreich 0.172375 0.072768 2.369 0.018
L1.Oberösterreich 0.138328 0.071082 1.946 0.052
L1.Salzburg 0.288996 0.037277 7.753 0.000
L1.Steiermark 0.035522 0.048666 0.730 0.465
L1.Tirol 0.163619 0.039473 4.145 0.000
L1.Vorarlberg 0.099534 0.033853 2.940 0.003
L1.Wien 0.068025 0.062857 1.082 0.279
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056439 0.041787 1.351 0.177
L1.Burgenland 0.039535 0.027739 1.425 0.154
L1.Kärnten 0.051079 0.014706 3.473 0.001
L1.Niederösterreich 0.219288 0.057859 3.790 0.000
L1.Oberösterreich 0.294114 0.056518 5.204 0.000
L1.Salzburg 0.043863 0.029639 1.480 0.139
L1.Steiermark 0.000039 0.038695 0.001 0.999
L1.Tirol 0.143766 0.031385 4.581 0.000
L1.Vorarlberg 0.071857 0.026917 2.670 0.008
L1.Wien 0.080864 0.049978 1.618 0.106
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174384 0.049913 3.494 0.000
L1.Burgenland -0.002652 0.033132 -0.080 0.936
L1.Kärnten -0.062469 0.017566 -3.556 0.000
L1.Niederösterreich -0.077153 0.069109 -1.116 0.264
L1.Oberösterreich 0.188762 0.067508 2.796 0.005
L1.Salzburg 0.058185 0.035403 1.644 0.100
L1.Steiermark 0.234318 0.046219 5.070 0.000
L1.Tirol 0.498768 0.037488 13.305 0.000
L1.Vorarlberg 0.044885 0.032151 1.396 0.163
L1.Wien -0.054675 0.059697 -0.916 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160643 0.057703 2.784 0.005
L1.Burgenland -0.008840 0.038304 -0.231 0.817
L1.Kärnten 0.066549 0.020308 3.277 0.001
L1.Niederösterreich 0.206559 0.079896 2.585 0.010
L1.Oberösterreich -0.070001 0.078044 -0.897 0.370
L1.Salzburg 0.210882 0.040928 5.152 0.000
L1.Steiermark 0.120509 0.053433 2.255 0.024
L1.Tirol 0.072591 0.043339 1.675 0.094
L1.Vorarlberg 0.119407 0.037169 3.213 0.001
L1.Wien 0.123103 0.069014 1.784 0.074
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358653 0.033085 10.840 0.000
L1.Burgenland 0.007041 0.021962 0.321 0.749
L1.Kärnten -0.023437 0.011644 -2.013 0.044
L1.Niederösterreich 0.214547 0.045810 4.683 0.000
L1.Oberösterreich 0.198953 0.044748 4.446 0.000
L1.Salzburg 0.044238 0.023467 1.885 0.059
L1.Steiermark -0.013807 0.030637 -0.451 0.652
L1.Tirol 0.104299 0.024849 4.197 0.000
L1.Vorarlberg 0.071576 0.021312 3.359 0.001
L1.Wien 0.039855 0.039570 1.007 0.314
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038859 0.139486 0.192093 0.151283 0.118186 0.102965 0.064237 0.217062
Kärnten 0.038859 1.000000 -0.007340 0.132063 0.039264 0.093916 0.432882 -0.053647 0.097203
Niederösterreich 0.139486 -0.007340 1.000000 0.334145 0.141297 0.292475 0.096271 0.179928 0.313001
Oberösterreich 0.192093 0.132063 0.334145 1.000000 0.228300 0.325730 0.176275 0.167431 0.261433
Salzburg 0.151283 0.039264 0.141297 0.228300 1.000000 0.143239 0.112832 0.145281 0.123839
Steiermark 0.118186 0.093916 0.292475 0.325730 0.143239 1.000000 0.146656 0.137590 0.071004
Tirol 0.102965 0.432882 0.096271 0.176275 0.112832 0.146656 1.000000 0.112704 0.142617
Vorarlberg 0.064237 -0.053647 0.179928 0.167431 0.145281 0.137590 0.112704 1.000000 0.002320
Wien 0.217062 0.097203 0.313001 0.261433 0.123839 0.071004 0.142617 0.002320 1.000000